#include "Metgine/Core/World.hpp"

using namespace Math;

namespace Metgine
{
namespace Core
{


World::World()
{
    m_gravity = Vector2f(0, DEFAULT_GRAVITY);

//    m_physWorld= new b2World((b2Vec2&)m_gravity, true);
}

World::~World()
{

}

bool World::Update(float elapsedTime)
{
    for (std::list<Object*>::iterator i = m_objects.begin(); i != m_objects.end(); ++ i)
    {
        ((Object*)*i)->Update(elapsedTime);
        return true;
    }

 	return false;
}

void World::AddObject(Object* object)
{
    if (object)
    {
        object->BuildPhysBody();
        m_objects.insert(m_objects.end(), object);
    }
}

void World::AddCreatedObject(Object* object)
{

    if (object)
        m_pendingObjects.push_back(object);

}

void World::RemoveAllObjects()
{

    for (std::list<Object*>::iterator i = m_objects.begin(); i != m_objects.end(); ++ i)
        delete *i;

    m_objects.clear();

}

void World::SetBackground(ImageResource* farImage, ImageResource* nearImage)
{
}

void World::CameraMoved(const Vector2f& newPosition)
{
}

Object* World::GetObjectAtPosition(const Vector2f& position)
{
    return NULL;
}

void World::Render()
{
    for (std::list<Object*>::iterator i = m_objects.begin(); i != m_objects.end(); ++ i)
        ((Object*)*i)->Render();
}

/*b2World* World::GetPhysWorld() const
{
    return m_physWorld;
}
*/
Vector2f World::Gravity()
{
    return m_gravity;
}

void World::SetGravity(Vector2f gravity)
{
//    m_physWorld->SetGravity((b2Vec2&)gravity);
}

int World::WidthInPixels()
{
    return 256;
}

int World::HeightInPixels()
{
    return 224;
}

}; // Core
}; // Metgine
